package com.ruoyi.project.bill.controller;


import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.bill.domain.BillForm;
import com.ruoyi.project.bill.service.IBillFormService;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 单据表单Controller
 * 
 * @author ruoyi
 * @date 2025-07-03
 */
@RestController
@RequestMapping("/form")
@Slf4j
public class BillFormController extends BaseController
{
    @Autowired
    private IBillFormService billFormService;

    /**
     * 查询单据表单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BillForm billForm)
    {

        startPage();
        List<BillForm> list = billFormService.selectBillFormList(billForm);
        return getDataTable(list);
    }

    /**
     * 导出单据表单列表
     */
    @Log(title = "单据表单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BillForm billForm)
    {

        List<BillForm> list = billFormService.selectBillFormList(billForm);
        ExcelUtil<BillForm> util = new ExcelUtil<BillForm>(BillForm.class);
        util.exportExcel(response, list, "单据表单数据");
    }

    /**
     * 获取单据表单详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(billFormService.selectBillFormById(id));
    }

    /**
     * 新增单据表单
     */
    @Log(title = "单据表单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BillForm billForm)
    {
        String msg = billFormService.insertBillForm(billForm);
        return  StringUtils.isNull(msg) || StringUtils.isEmpty(msg)? success(): error(msg);
    }

    /**
     * 修改单据表单
     */
    @Log(title = "单据表单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BillForm billForm)
    {
        String msg = billFormService.updateBillForm(billForm);
        return  StringUtils.isNull(msg) || StringUtils.isEmpty(msg)? success(): error(msg);
    }

    /**
     * 删除单据表单
     */
    @Log(title = "单据表单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        String msg = (billFormService.deleteBillFormByIds(ids));
        return  StringUtils.isNull(msg) || StringUtils.isEmpty(msg)? success(): error(msg);
    }


}
